package com.sdx.console.promote.service;

import java.util.List;

import org.beetl.sql.core.engine.PageQuery;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ibeetl.admin.core.util.PlatformException;

import com.sdx.console.promote.dao.PromotePersonDao;
import com.sdx.console.promote.entity.PromotePerson;
import com.ibeetl.admin.core.service.BaseService;

/**
 * 推广人 Service
 */

@Service
@Transactional
public class PromotePersonService extends BaseService<PromotePerson>{

    @Resource
	private PromotePersonDao promotePersonDao;

    public PageQuery<PromotePerson>queryByCondition(PageQuery query){
        PageQuery ret =  promotePersonDao.queryByCondition(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public void batchDelPromotePerson(List<String> ids){
        try {
            promotePersonDao.batchDelPromotePersonByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除推广人失败", e);
        }
    }

	public List<PromotePerson> all() {
		return promotePersonDao.all();
		}

    public void updateChannel(String customerId,String channelCode){
        PromotePerson person = new PromotePerson();
        person.setCustomerId(customerId);
        PromotePerson promotePerson = sqlManager.templateOne(person);
        if(promotePerson!=null){
            person.setChannelCode(channelCode);
            updateTemplate(person);
            promotePersonDao.updateFinTranChannel(channelCode, promotePerson.getChannelCode(), promotePerson.getPromoteCode());
        }

    }
}